import Main from '@/components/main';
const Component = {
	'404': () => import('@/view/error-page/404.vue')
};

export function menuFormat(array) {
	var temp = [];
	for (var i = 0; i < array.length; i++) {
		if (array[i].type == 1) {
			continue;
		}
		let newobj = {
			path: (array[i].level == 1 ? '/' : '') + array[i].url,
			name: array[i].url,
			meta: {
				icon: array[i].icon,
				title: array[i].name
			}
		};
		if (array[i].level == 1) {
			newobj['component'] = Main;
		} else {
			if (Component[array[i].url]) {
				newobj['component'] = Component[array[i].url];
			} else {
				newobj['component'] = Component['404'];
			}
		}
		if (array[i].lists && array[i].lists.length > 0) {
			newobj['children'] = menuFormat(array[i].lists);
		}

		temp.push(newobj);
	}
	return temp;
}
